<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>   
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
/*
*
* Copyright (c) 2011 Vaulting Systems International
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy 
* of this software and associated documentation files (the "Software"), to deal 
* in the Software without restriction, including without limitation the rights 
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
* of the Software, and to permit persons to whom the Software is furnished to do  
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all  
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE  
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><s:text name="dashboard.title" /></title>
	<sj:head jqueryui="true" jquerytheme="smoothness"  />
    
    <script type="text/javascript">

	    function openUploadDialog(){       
	    	$('#uploaddialog').dialog('open'); 
	    }; 
	    
	    function closeUploadDialog(){       
	    	$('#uploaddialog').dialog('close'); 
	    	$("#resourceGrid").trigger("reloadGrid");    
	    }; 	

	    $.subscribe('beforeDialogOpen', function(event,data) {          
			$('span.ui-button-text').css('font-size', '12px');
		}); 
	    
	    $.subscribe('gridloaded', function(event,data) {
		    var blankTargets = $("a[target='_blank']");
	    	$(blankTargets).addClass('normalLink');
	    	$(blankTargets).css('font-size', '12px');
	    });

	    function disablePassphrase(){
		    $("#uploadPassphrase").attr('disabled', 'disabled'); 
	    }		    

	    function enablePassphrase(){
		    $("#uploadPassphrase").removeAttr('disabled'); 
		    $("#uploadPassphrase").focus();
	    }	
	    	    
        function formatLink(cellvalue, options, rowObject) {
            var linkText = '<s:text name="resource.download.label" />';
            var downloadLink = "";
               
            if(rowObject.passphraseProtected.toUpperCase() == 'Y') {
            	downloadLink = "<a href='#' class='normalLink' style='font-size:14px;' onClick='javascript:openDownloadDialog(" + 
            		options.rowId +")'>" + linkText + "</a>";
            }
            else{
            	downloadLink = "<a class='normalLink' style='font-size:14px;' href='/SecureSave/download.action?resourceId="
                    + options.rowId + "' target='blank'>" + linkText + "</a>";
            }

            return downloadLink;
	    }
	    
	    function openDownloadDialog(rowId) {
	            $("#download_passphrase").load("/SecureSave/p/downloadPassphraseDialog.jsp?resourceId=" + rowId);
	            $("#download_passphrase").dialog('open');
	    }	    
    </script>
    
<style>

a.normalLink:link { color: #0000FF; font-size:14px; font-style:normal;
	font-weight:bold; text-decoration: underline }
a.normalLink:visited { color: #0000FF; font-size:14px; font-style:normal;
	font-weight:bold; text-decoration: underline }
a.normalLink:hover { color: #FF0000; font-size:14px; font-style:normal;
	font-weight:bold; text-decoration: underline }

#pg_resourceGrid_pager {font-size:12px;font-weight:bold;}
#jqgh_resourceGrid_fileDescription {font-size:12px;font-weight:bold;}
#jqgh_resourceGrid_filename {font-size:12px;font-weight:bold;}
#jqgh_resourceGrid_filetype {font-size:12px;font-weight:bold;}
#jqgh_resourceGrid_filelength {font-size:12px;font-weight:bold;}
#jqgh_resourceGrid_griddownloadlink {font-size:12px;font-weight:bold;}
#uploaddialog {font-size:12px;font-weight:normal;}
#ui-dialog-title-uploaddialog {font-size:12px;font-weight:bold;}
#ui-dialog-title-download_passphrase {font-size:12px;font-weight:bold;}
#download_passphrase {font-size:12px;font-weight:normal;}
</style>

</head>
<body bgColor="#ffffff" leftMargin="0" topMargin="0" rightMargin="0">
		<sj:dialog 
	        id="download_passphrase" 
	        title="Secure Save File Download" 
	        autoOpen="false" 
	        modal="true"
	        width="500"
	        resizable="false"
 			overlayOpacity="0.9"
 			onBeforeTopics="beforeDialogOpen" 
 			/>
	
        <div id="headline">
	        <h1 class="ui-state-default" style="background: none; border: none;"><s:text name="headline.title" /></h1>
	        <h4 class="ui-state-default" style="background: none; border: none;"><s:text name="headline.version" /></h4>
        </div>
               
           <div > 
			 <s:url id="downloadurl" action="download"/>	               
		     <s:url id="resourceremoteurl" action="searchResource"/>
		     <s:url id="resourceediturl" action="editResource"/>
		     <sjg:grid
		    	id="resourceGrid"
		    	width="850" 
		    	cssStyle="font-size:10px;"
		    	caption="Uploaded Files"
		    	dataType="json"
		    	href="%{resourceremoteurl}"
		    	pager="true"
		    	navigator="true"
		    	navigatorAdd="false"
		    	navigatorEdit="false"
		    	navigatorView="true"
		    	navigatorViewOptions="{
		    		caption:'File Details',
		    		height:300,
		    		width:600
				}"
		    	navigatorDelete="true"
		    	navigatorDeleteOptions="{
		    		caption:'Delete File',
		    		height:300,
		    		width:600,
		    		modal:true,
		    		reloadAfterSubmit:true,
		    		closeAfterEdit:true,
					afterSubmit: function(response, postdata) {
									return [true,'Delete successful'];
		                         }
				}"
		    	navigatorSearch="true"
				navigatorSearchOptions="{
					height:300,
		    		width:600,
					multipleSearch:true
				}"
		    	gridModel="gridModel"
		    	rowList="10,15,20"
		    	rowNum="15"
		    	editurl="%{resourceediturl}"
		    	editinline="false"
		    	multiselect="true"
		    	viewrecords="true"
		    	onGridCompleteTopics="gridloaded"
		    >
		    	<sjg:gridColumn 
		    		name="id" 
		    		index="id" 
		    		title="ID" 
		    		hidden="true"
		    		key="true"
		    		formatter="integer" 
		    		sortable="false" />
		    	<sjg:gridColumn  
		    		cssStyle="font-size:10px;font-weight:bold;"
		    		name="fileDescription" 
		    		index="fileDescription" 
		    		title="Description" 
		    		editable="true" 
		    		edittype="text"  
		    		sortable="true" 
		    		search="true" 
		    		searchoptions="{sopt:['eq','cn','bw','ew','le','lt','ge','gt','ne']}"/>
		    	<sjg:gridColumn  
		    		cssStyle="font-size:10px;"
		    		name="filename" 
		    		index="filename" 
		    		title="File Name" 
		    		editable="true" 
		    		edittype="text" 
		    		sortable="true" 
		    		search="true" 
		    		searchoptions="{sopt:['eq','cn','bw','ew','le','lt','ge','gt','ne']}"/>
		    	<sjg:gridColumn  
		    		cssStyle="font-size:10px;"
		    		name="filetype" 
		    		index="filetype" 
		    		title="File Type" 
		    		editable="true" 
		    		edittype="text" 
		    		sortable="true" 
		    		search="true" 
		    		searchoptions="{sopt:['eq','cn','bw','ew','le','lt','ge','gt','ne']}"/>
		       	<sjg:gridColumn  
		       		cssStyle="font-size:10px;"
		    		name="filelength" 
		    		index="filelength" 
		    		title="Size" 
		    		align="right"
		     		sortable="false" 
		     		editable="false" 
		     		formatter="integer" 
		     		formatoptions=	"{
		    			thousandsSeparator:','
		    						}"
		     		/>
		     	<sjg:gridColumn  
		    		name="resourceUri" 
		    		index="resourceUri" 
		    		title="Resource Uri" 
		    		hidden="true"
		    		editable="false" 
		    		sortable="false" />   		
		     	<sjg:gridColumn  
		    		name="bucketUri" 
		    		index="bucketUri" 
		    		title="Bucket Uri" 
		    		hidden="true"
		    		editable="false" 
		    		sortable="false" />   
		     	<sjg:gridColumn  
		    		name="passphraseProtected" 
		    		index="passphraseProtected" 
		    		title="Passphrase Protected" 
		    		hidden="true"
		    		editable="false" 
		    		sortable="false" />  
		     	<sjg:gridColumn 
		    		name="griddownloadlink" 
		    		index="griddownloadlink" 
					title="Download"
		    		formatter="formatLink"
		    		/>   		


		     </sjg:grid>
 		   </div>  
 		<br />        
		<div class="ui-state-default" style="background: none; border: none;">
    		<sj:dialog id="uploaddialog" 
 				title="Secure Save File Upload" 
 				autoOpen="false" 
 				modal="true"
 				width="500"
 				resizable="false"
 				overlayOpacity="0.9"
 				onBeforeTopics="beforeDialogOpen"
 				> 
 				<br />
				<s:form action="upload" method="post" enctype="multipart/form-data">
				    <s:textfield name="fileDescription" id="fileDescription" value="%{fileDescription}" 
    					label="%{getText('resource.file.description')}" size="60" maxlength="255"/>
		
				    <s:file name="upload" label="%{getText('resource.upload.file')}" size="60" />
					
					<tr><td colspan="2">
					<s:text name="resource.file.passphrase.question" />
					</td></tr>
					
					<tr><td colspan="2">
					<input type="radio" name="pphrase" id="pphrase" value="yes" onclick="javascript:enablePassphrase();"/> Yes
					</td></tr>

					<tr><td colspan="2">					
					<input type="radio" name="pphrase" id="pphrase" value="no" onclick="javascript:disablePassphrase();" checked="checked" /> No
					</td></tr>
					
				    <s:password name="uploadPassphrase" id="uploadPassphrase" value="%{uploadPassphrase}" disabled="true"
    					label="%{getText('resource.file.passphrase')}" size="60" maxlength="255"/>
				    <s:submit/>
				</s:form>
				<div><s:text name="resource.upload.limit" /></div>
				
    		</sj:dialog>   
			<a id="uploaddialoglink" class="normalLink"
 				href='javascript:openUploadDialog()'><s:text name="resource.new.upload" /></a>
		</div>
		<br />
		<div class="ui-state-default" style="background: none; border: none;"> 
 			<a id="administrationlink" class="normalLink"
 				href='<s:url action="administration"/>'><s:text name="resource.administration" /></a>
 		</div>
		<br />

      <div align="center" class="ui-state-default">
        <s:text name="footer.copy" /><br/>
        <a class="normalLink" href='<s:url value="/j_spring_security_logout"/>'><s:text name="logout.label" /></a>
      </div>

</body>

</html>